package com.xh.demo.controller;

import com.xh.demo.commons.model.Result;
import com.xh.demo.model.table.User;
import com.xh.demo.service.ClientUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wen
 * @apiNote TestClientController
 * @since 2021-08-07
 */
@Slf4j
@RestController
@RequestMapping("/client")
@Api(tags = "客户端用户相关-接口")
public class TestClientController {

    @Autowired
    private ClientUserService clientUserService;

    @PostMapping("/user")
    @ApiOperation(value = "保存用户信息", notes = "555:系统未知异常")
    public Result<User> saveUser(@RequestBody User user) {
        User lakeUser = clientUserService.saveUser(user);
        log.info(lakeUser.toString());
        return Result.success(lakeUser);
    }

    @GetMapping("/user/{id}")
    @ApiOperation(value = "查询用户信息", notes = "555:系统未知异常")
    public Result<User> getUserById(@PathVariable("id") Long id) {
        User lakeUser = clientUserService.getUserByIdV2(id);
        return Result.success(lakeUser);
    }

    @GetMapping("/sign/user/{id}")
    @ApiOperation(value = "查询用户信息", notes = "555:系统未知异常")
    public Result<User> getUserByIdSign(@PathVariable("id") Long id) {
        User lakeUser = clientUserService.getUserByIdSign(id);
        return Result.success(lakeUser);
    }

    @GetMapping("/timestamp/user/{id}")
    @ApiOperation(value = "查询用户信息", notes = "555:系统未知异常")
    public Result<User> getUserByIdTimestamp(@PathVariable("id") Long id) {
        User lakeUser = clientUserService.getUserByIdTimestamp(id);
        return Result.success(lakeUser);
    }

    @GetMapping("/user")
    @ApiOperation(value = "查询用户信息", notes = "555:系统未知异常")
    public Result<User> getUserByIdV2(@RequestParam("id") Long id) {
        User lakeUser = clientUserService.getUserById(id);
        return Result.success(lakeUser);
    }


}
